package com.iversonx.scene_1.v2.decoration.builder;

import com.iversonx.scene_1.entity.Matter;
import com.iversonx.scene_1.v2.decoration.DecorationPackage;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public abstract class AbstractDecorationPackageBuilder {
    public  boolean support(Integer level) {
        return level == level();
    }
    
    protected abstract int level();
    
    protected abstract String getGrade();
    
    protected abstract Matter appendCeiling();
    
    protected abstract Matter appendCoat();
    
    protected Matter appendFloor() {
        return null;
    }
    
    protected Matter appendTile() {
        return null;
    }
    
    public DecorationPackage build(BigDecimal area) {
        Matter ceiling = appendCeiling();
        Matter coat = appendCoat();
        Matter floor = appendFloor();
        Matter tile = appendTile();
    
        BigDecimal price = BigDecimal.ZERO;
        price = price.add(area.multiply(new
                BigDecimal("0.2")).multiply(ceiling.price()));
        price = price.add(area.multiply(new
                BigDecimal("1.4")).multiply(coat.price()));
        
        List<Matter> list = new ArrayList<>();
        list.add(ceiling);
        list.add(coat);
        if(floor != null) {
            price = price.add(area.multiply(floor.price()));
            list.add(floor);
        }
    
        if(tile != null) {
            price = price.add(area.multiply(tile.price()));
            list.add(tile);
        }
        
        DecorationPackage decorationPackage = new DecorationPackage();
        decorationPackage.setGrade(getGrade());
        decorationPackage.setArea(area);
        decorationPackage.setList(list);
        decorationPackage.setPrice(price);
        decorationPackage.setLevel(level());
        return decorationPackage;
    }
}
